package com.xhh.user.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xhh.model.common.dtos.ResponseResult;
import com.xhh.model.common.enums.AppHttpCodeEnum;
import com.xhh.model.user.pojos.School;
import com.xhh.model.user.pojos.Student;
import com.xhh.user.mapper.SchoolMapper;
import com.xhh.user.mapper.StudentMapper;
import com.xhh.user.service.SchoolService;
import com.xhh.user.service.StudentService;
import org.springframework.stereotype.Service;

@Service
public class SchoolServiceImpl extends ServiceImpl<SchoolMapper, School> implements SchoolService {
    /**
     * 根据用户id获取招生单位
     * @param userId
     * @return
     */
    @Override
    public ResponseResult getSchByUId(Long userId) {
        // 1. 校验参数
        if (userId == null || userId == 0) {
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        // 2. 构建查询
        School school = lambdaQuery()
                .eq(School::getUserId, userId)
                .one();
        if (school == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST);
        }
        // 3. 返回结果
        return ResponseResult.okResult(school);
    }
}
